package com.example.HelloWorld;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

@WebServlet(name = "SecondServlet", value = "/secondServlet")
public class SecondServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //get参数小，post参数大，小的可以放到大的里面，所以推荐get里面调用post
        doPost(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("do post method-----------");
        Map<String, String[]> map = request.getParameterMap();
        Set<String> keys =  map.keySet();
        Iterator<String> iterator = keys.iterator();
        while (iterator.hasNext()){
            String key = iterator.next();
            //System.out.println("长度为:"+key.length());
            System.out.println(key+":"+map.get(key)[0]);
            if(key.equals("languages")){
                for (int i = 1; i < map.get(key).length; i++) {
                        System.out.println(key + ":" + map.get(key)[i]);
                }

            }

        }


    }


}
